# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libtheora
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.1
pkgrel=6
pkgdesc="An open video codec developed by the Xiph.org (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://xiph.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libogg"
         "${MINGW_PACKAGE_PREFIX}-libvorbis")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-SDL")
source=("https://downloads.xiph.org/releases/theora/${_realname}-${pkgver}.tar.bz2"
        libtheora-1.1.1-libpng16.patch
        001-example.patch)
sha256sums=('b6ae1ee2fa3d42ac489287d3ec34c5885730b1296f0801ae577a35193d3affbc'
            'e4c9a8dc798c596ed32a2a720020ae27a0e72f5add1a47cb8fadebe0e7180d7e'
            '5627d26c3316fef71bca037e1834bcba063dbf949ea9293820f0e68b13641105')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  sed -i "s,EXPORTS,," "win32/xmingw32/libtheoradec-all.def"
  sed -i "s,EXPORTS,," "win32/xmingw32/libtheoraenc-all.def"
  patch -p0 -i ${srcdir}/libtheora-1.1.1-libpng16.patch
  patch -p1 -i ${srcdir}/001-example.patch
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p ${srcdir}/build-$MINGW_CHOST
  cd "${srcdir}/build-$MINGW_CHOST"

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX}

  # parallel is broken (libtheoraenc is missing sometimes)
  make -j1
}

package() {
  cd "${srcdir}/build-$MINGW_CHOST"
  make install DESTDIR="${pkgdir}"
}
